package io.github.openfeign.restfulExam;

import feign.*;
import io.github.openfeign.restfulExam.GsonExpander;

import java.util.Map;

/**
 * 测试Feign生成的请求内容，使用burp suite直接进行抓包测试
 * 详细的生成请求可见测试类
 */
public class App {
    public static void main(String[] args) {

    }

    public static class User {
        String username;
        String uid;

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getUid() {
            return uid;
        }

        public void setUid(String uid) {
            this.uid = uid;
        }

//        @Override
//        public String toString() {
//            JsonObject jsonObject = new JsonObject();
//            jsonObject.addProperty("username", this.username);
//            jsonObject.addProperty("uid", this.uid);
//            return jsonObject.toString();
//        }
    }

    public interface FeignTestInterface {
        @RequestLine("GET /echo/{param1}")
        @Headers("Accept: application/json")
        public void method1(@Param("param1") String param1);


        @RequestLine("GET /method2")
        @Headers("Accept: application/json")
        public void method2(@QueryMap Map map);

        @RequestLine("GET /testHeadMap")
        @Headers("Accept: application/json")
        public void testHeadMap(@HeaderMap Map map);

        @RequestLine("POST /posttest")
        @Body("{body}")
        @Headers("Accept: application/json")
        public void testBody(String body);

        @RequestLine("POST /posttest")
        @Headers("Accept: application/json")
//        @Body("{user}")
        public void testObjectBody(User user);

        @RequestLine("POST /testMultiFieldBody")
        @Headers("Content-Type: application/json")
        @Body("%7B\"param1\":\"{p1}\",\"param1\":\"{p2}\",\"variables\":{user}%7D")
        public void testMultiFieldBody(@Param("p1") String p1, @Param("p2") String p2, @Param(value = "user", expander = GsonExpander.class) User user);
    }


}
